-module(erlang_binary).

-include_lib("eunit/include/eunit.hrl").

-define(FILENAME, "test/construction/" ?MODULE_STRING ".yaml").

setup() ->
    application:start(yamerl).

simple_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
           [
            [
             {"foo",<<"bar">>},
             {"canonical",
              <<71, 73, 70, 56, 57, 97, 12, 0, 12, 0, 132, 0, 0, 255, 255, 247, 245,
                245, 238, 233, 233, 229, 102, 102, 102, 0, 0, 0, 231, 231, 231, 94,
                94, 94, 243, 243, 237, 142, 142, 142, 224, 224, 224, 159, 159, 159,
                147, 147, 147, 167, 167, 167, 158, 158, 158, 105, 105, 105, 99, 99,
                99, 163, 163, 163, 132, 132, 132, 255, 254, 249, 255, 254, 249,
                255, 254, 249, 255, 254, 249, 255, 254, 249, 255, 254, 249, 255,
                254, 249, 255, 254, 249, 255, 254, 249, 255, 254, 249, 255, 254,
                249, 255, 254, 249, 255, 254, 249, 255, 254, 249, 33, 254, 14, 77,
                97, 100, 101, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 0, 44, 0, 0,
                0, 0, 12, 0, 12, 0, 0, 5, 44, 32, 32, 142, 129, 48, 158, 227, 64, 20,
                232, 105, 16, 196, 209, 138, 8, 28, 207, 128, 77, 36, 122, 239, 255,
                48, 133, 112, 184, 176, 49, 102, 13, 27, 206, 1, 195, 1, 30, 16, 39,
                32, 130, 10, 1, 0, 59>>}
            ]
           ],
           yamerl_constr:file(?FILENAME, [{detailed_constr, false}])
        )
      ]
    }.

detailed_test_() ->
    {setup,
      fun setup/0,
      [
        ?_assertMatch(
           [
            {yamerl_doc,
             {yamerl_map, yamerl_node_map, "tag:yaml.org,2002:map",
              [{line, 1}, {column, 1}],
              [{{yamerl_str, yamerl_node_str, "tag:yaml.org,2002:str",
                 [{line, 1}, {column, 1}],
                 "foo"},
                {yamerl_binary, yamerl_node_binary, "tag:yaml.org,2002:binary",
                 [{line, 1}, {column, 15}],
                 <<"bar">>}},
               {{yamerl_str, yamerl_node_str,  "tag:yaml.org,2002:str",
                 [{line, 5}, {column, 1}],
                 "canonical"},
                {yamerl_binary, yamerl_node_binary, "tag:yaml.org,2002:binary",
                 [{line, 5}, {column, 21}],
                 <<71, 73, 70, 56, 57, 97, 12, 0, 12, 0, 132, 0, 0,
                   255, 255, 247, 245, 245, 238, 233, 233, 229,
                   102, 102, 102, 0, 0, 0, 231, 231, 231, 94, 94, 94,
                   243, 243, 237, 142, 142, 142, 224, 224, 224,
                   159, 159, 159, 147, 147, 147, 167, 167, 167,
                   158, 158, 158, 105, 105, 105, 99, 99, 99, 163,
                   163, 163, 132, 132, 132, 255, 254, 249, 255,
                   254, 249, 255, 254, 249, 255, 254, 249, 255,
                   254, 249, 255, 254, 249, 255, 254, 249, 255,
                   254, 249, 255, 254, 249, 255, 254, 249, 255,
                   254, 249, 255, 254, 249, 255, 254, 249, 255,
                   254, 249, 33, 254, 14, 77, 97, 100, 101, 32, 119,
                   105, 116, 104, 32, 71, 73, 77, 80, 0, 44, 0, 0, 0,
                   0, 12, 0, 12, 0, 0, 5, 44, 32, 32, 142, 129, 48,
                   158, 227, 64, 20, 232, 105, 16, 196, 209, 138, 8,
                   28, 207, 128, 77, 36, 122, 239, 255, 48, 133,
                   112, 184, 176, 49, 102, 13, 27, 206, 1, 195, 1,
                   30, 16, 39, 32, 130, 10, 1, 0, 59>>}}]}
            }
           ],
          yamerl_constr:file(?FILENAME, [{detailed_constr, true}])
        )
      ]
    }.
